# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ResIL

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.9
pkgrel=3
pkgdesc="Library for reading several different image formats (mingw-w64)"
arch=('any')
url="http://resil.sourceforge.net"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-libpng"
        "${MINGW_PACKAGE_PREFIX}-libmng"
        "${MINGW_PACKAGE_PREFIX}-openexr"
        "${MINGW_PACKAGE_PREFIX}-jasper"
        "${MINGW_PACKAGE_PREFIX}-lcms"
        "${MINGW_PACKAGE_PREFIX}-SDL"
        #"${MINGW_PACKAGE_PREFIX}-allegro"
        )
provides=("${MINGW_PACKAGE_PREFIX}-DevIL")
conflicts=("${MINGW_PACKAGE_PREFIX}-DevIL")
options=('staticlibs' 'strip')
source=("http://downloads.sourceforge.net/resil/ResIL-${pkgver}.zip"
        fix-il_gif.patch)
md5sums=('15640d11900fa75107f4ad2109d71ecb'
         'ac530e0b2a453b194c5d945a62fcb6ea')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  #mv include/IL/config.h include/IL/config.h.in
  patch -p1 -i ${srcdir}/fix-il_gif.patch

  #libtoolize --copy --force
  #aclocal -I m4
  #automake --add-missing
  #autoconf
  autoreconf -fi
}

build() {
  mkdir $srcdir/build-${MINGW_CHOST}
  cd "$srcdir/build-${MINGW_CHOST}"

  if [[ $CARCH == i686 ]]; then
    local _conf="--disable-sse3"
  else
    local _conf=""
  fi
  export lt_cv_deplibs_check_method='pass_all'
  #CFLAGS+=" -I ${MINGW_PREFIX}/include/allegro5"
  #CPPFLAGS+=" -I ${MINGW_PREFIX}/include/allegro5"
  #CXXFLAGS+=" -I ${MINGW_PREFIX}/include/allegro5"
  CXXFLAGS+=" -std=c++11"

  ../${_realname}-${pkgver}/configure --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-ILU \
    --enable-ILUT \
    --enable-directx8=no \
    --enable-directx9=yes \
    --enable-wdp=no \
    --disable-allegro \
    --with-sdl-prefix=${MINGW_PREFIX} \
    --without-x \
    ${_conf}
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
